/*
* @Author: zhangsai
* @Date: 2018/2/26
* @Last Modified by: zhangsai
* @Last Modified time: 2018/2/26
* @description: 报告管理
*/
<template>
    <div>
        <div class="right">
            <div class="ca-file-main ca-box ca-p-22" v-loading.body="fullLoading">
                <div class="ca-title">
                    <el-row>
                        <el-col :span="4"><h3>{{title}}</h3></el-col>
                        <el-col :span="12">
                            <el-input placeholder="请输入关键词,支持模糊查询" v-model="params.reportName">
                                <el-button slot="append" icon="el-icon-search" @click="getReportList" ></el-button>
                            </el-input>
                        </el-col>
                        <el-col :span="6" class="pull-right">
                            <div class="ca-inline-block ca-m-r-10 ">
                                <csUploadBtn
                                    :fileType="this.reportType"
                                    :isShowFileChildType="false"
                                    uploadType="txt,ppt,pptx,jpg,gif,png,doc,docx,jpge,xls,xlsx,rar,pdf"
                                    @getFileList="getDefaultInfo"
                                    :disabled="!isAuthEdit"
                                ></csUploadBtn>
                            </div>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="24">
                            <slot></slot>
                        </el-col>
                    </el-row>
                </div>
                <div class="ca-file-ul">
                    <el-row class="ca-file-row" :gutter="20" v-for="(file, index) in fileList.resultData" :key="index">
                        <el-col :span="4" class="upload-time">{{file.uploadTime|moment('YYYY-MM-DD')}}</el-col>
                        <el-col :span="1">
                            <tz-icon-file-type class="ca-m-r-5" :fileType="file.reportName"></tz-icon-file-type>
                        </el-col>
                        <el-col :span="8">
                            <div class="ca-text-over-flow-ellipsis">
                                <span class="ca-font-size-16 ca-pointer"
                                      @click="previewFileCheck(file.id, file.reportName)">{{file.reportName}}</span>
                            </div>
                        </el-col>
                        <!--部门 母基金版本不显示部门-->
                        <!--<el-col :span="4" v-if="reportType!=10007" >-->
                            <!--<div class="ca-text-over-flow-ellipsis">{{file.deptName}} &nbsp;</div>-->
                        <!--</el-col>-->
                        <!--上传人-->
                        <el-col :span="4">
                            <div class="ca-text-over-flow-ellipsis">{{file.uploadUserName}}</div>
                        </el-col>
                        <!--公司制度确定按钮-->
                        <el-col :span="3" class="ca-pull-right ca-align-right" v-if="reportType==10007">
                            <el-button type="primary" size="small"
                                       v-if="file.validationStatus != 1"
                                       @click="reportConfirm(file)"
                                       :disabled="!isAuthSubmit"
                            >点击确认</el-button>
                            <el-button type="primary" size="small" v-else :disabled="true">已确认</el-button>
                        </el-col>
                        <!--操作-->
                        <el-col :span="3" class="ca-pull-right ca-align-right">
                            <el-button class="ca-download ca-m-r-10" @click="downloadFile(file.id)" :disabled="!isAuthDow"></el-button>
                            <el-button class="ca-table-btn" @click="deleteFile(file.id)"
                                       :disabled="(file.uploadUser != userId || !isAuthEdit) && userId !=1">
                                <i class="fa fa-times"></i>
                            </el-button>
                        </el-col>
                    </el-row>
                    <div class="ca-align-right">
                        <el-pagination
                            @current-change="handleCurrentChange"
                            :current-page="params.pageIndex"
                            :page-size="params.pageSize"
                            layout="total, prev, pager, next, jumper"
                            :total="fileList.totalCount">
                        </el-pagination>
                    </div>
                </div>
            </div>
        </div>

    </div>
</template>

<script type="text/ecmascript-6">
import {api} from './api';
import {STATUS_HTTP_SUCCESS, apiHttp} from '__service/csHttp';
import { isNoAuth } from '__service/utils';
import mined from './mixin';
let PARAMS = {
    reportName: '',
    reportType: '',
    pageIndex: 1,
    pageSize: 10,
}
export default {
    mixins: [mined],
    data() {
        let isAuthSee = false; // 查看权限
        let isAuthEdit = false; // 编辑权限
        let isAuthDow = false; // 下载权限
        switch (Number(this.$route.params.id)) {
            case 10023 :
                isAuthSee = isNoAuth('报告管理-研究报告-查看');
                isAuthEdit = isNoAuth('报告管理-研究报告-编辑');
                isAuthDow = isNoAuth('报告管理-研究报告-下载');
                break;
            case 10035 :
                isAuthSee = isNoAuth('报告管理-风控报告-查看');
                isAuthEdit = isNoAuth('报告管理-风控报告-编辑');
                isAuthDow = isNoAuth('报告管理-风控报告-下载');
                break;
            case 10007 :
                isAuthSee = isNoAuth('报告管理-公司制度-查看');
                isAuthEdit = isNoAuth('报告管理-公司制度-编辑');
                isAuthDow = isNoAuth('报告管理-公司制度-下载');
                break;
            case 10031 :
                isAuthSee = isNoAuth('报告管理-重要决议-查看');
                isAuthEdit = isNoAuth('报告管理-重要决议-编辑');
                isAuthDow = isNoAuth('报告管理-重要决议-下载');
                break;
        }
        return {
            reportType: this.$route.params.id,
            title: '',
            departmentList: this.$store.state.user.department.departmentList,
            isAuthSee: isAuthSee,
            isAuthEdit: isAuthEdit,
            isAuthDow: isAuthDow,
            isAuthSubmit: isNoAuth('报告管理-公司制度-制度确认'),
            userId: this.$store.state.user.id
        }
    },
    watch: {
        // 如果路由有变化，会再次执行该方法
        $route() {
            this.reportType = this.$route.params.id;
            this.params = Object.assign({}, PARAMS, {reportType: this.reportType});
            this.getDefaultInfo();
            this.getTitle();
        },
    },
    props: {},
    mounted() {
        if (!this.isAuthSee) {
            this.$message.error('没有此页面的操作权限');
            this.$router.go(-1);
            return;
        }
        this.getDefaultInfo();
        this.getTitle();
    },
    methods: {
        getTitle() {
            let title = '';
            switch (Number(this.$route.params.id)) {
                case 10023 : title = '研究报告';
                    break;
                case 10035 : title = '风控报告';
                    break;
                case 10007 : title = '公司制度';
                    break;
                case 10031 : title = '重要决议';
                    break;
            }
            this.title = title;
        },
        // 公司制度 点击确认
        reportConfirm(item) {
            this.$confirm('我已知晓公司规章制度，并愿意遵守，如违反愿承担相应责任!', '确认书', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(async () => {
                let params = {
                    fileId: item.id,
                    status: item.validationStatus,
                    userId: this.$store.state.user.id
                };
                let resData = await apiHttp(api.SET_REPORT_LIST, params);
                if (resData.resCode === STATUS_HTTP_SUCCESS) {
                    this.$message.success('已确认');
                    this.getReportList();
                }
            });
        }
    },
    components: {
        'csUploadBtn': require('__components/upload-btn'),
    },
}
</script>
<style rel="stylesheet/scss" lang="scss" scoped>

</style>
